package net.huashitong.ssydt.security.utils;

import net.huashitong.ssydt.provider.utils.encrypt.EncodeUtils;

import java.security.SecureRandom;
import java.util.UUID;

/**
 * @author <a href="mailto:yhy23456@163.com">huiyang.yu</a>
 * @since 2017.08.14
 */
public class UUIDGenerator {

    private static SecureRandom random = new SecureRandom();

    public UUIDGenerator() {
    }

    public static String uuid() {
        return UUID.randomUUID().toString();
    }

    public static String uuid2() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    public static long randomLong() {
        return Math.abs(random.nextLong());
    }

    public static String randomBase62(int length) {
        byte[] randomBytes = new byte[length];
        random.nextBytes(randomBytes);
        return EncodeUtils.encodeBase62(randomBytes);
    }
}
